;layui.define(function(e) {
    layui.use(['table','layer','form','laydate','upload'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate
            ,upload = layui.upload;
        //展示已知数据
        table.render({
            elem: '#idTest'
            ,cols: [[ //标题栏
                {field: 'logo', title: 'LOGO'}
                ,{field: 'brand', title: '品牌'}
                ,{field: 'trade', title: '厂商'}
                ,{field: 'carSeries', title: '车系'}
                ,{field: 'carType', title: '车型'}
                ,{field: 'guidePrice', title: '指导价(元)'}
                ,{field: 'servicingTime', title: '维护时间'}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:178, align:'center', toolbar: '#barDemo'}
            ]]
            ,height: 'full-350'
            ,cellMinWidth: 120
            ,data: [{
                "logo": "10001"
                ,"brand": "杜甫"
                ,"trade": "xianxin@layui.com"
                ,"carSeries": "男"
                ,"carType": "浙江杭州"
                ,"guidePrice": "人生恰似一场修行"
                ,"servicingTime": "116"
                ,"tool": "2016-10-14"
            }]
            ,page: true //是否显示分页
        });
        //监听新增按钮

        //监听表格复选框选择
        table.on('checkbox(listTable)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(listTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '详情'
                    ,content: 'detail.html'
                    ,area: ['500px', '500px']
                    ,btn: ['确定', '取消']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find("input[name=brand]").val(data.brand)
                        body.find("input[name=trade]").val(data.trade)
                        body.find("input[name=carSeries]").val(data.carSeries)
                    }
                    ,yes: function (index,layero) {

                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                    ,btn1: function (index,layero) {
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                layer.full(index);
            } else if(obj.event === 'delete'){
                layer.confirm('确定删除吗?', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'config'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '配置'
                    ,content: 'paramManage.html'
                    ,area: ['500px', '500px']
                    ,btn: ['确定', '取消']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                    }
                });
                layer.full(index);
            }else if(obj.event === 'edit'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '编辑'
                    ,content: 'editParam.html'
                    ,area: ['500px', '500px']
                    ,btn: ['确定', '取消']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        var paramData = ['参数1','参数2'];
                        var param_add_box ='<form class="layui-form">' +
                            '                   <div class="param_add_box">\n' +
                            '                        <div class="layui-input-inline layui-col-space20">\n' +
                            '                            <div class="layui-input-inline">\n' +
                            '                                <input type="text" class="layui-input" name="maintain_base_choose_param_edit">\n' +
                            '                            </div>\n' +
                            '                            <div class="layui-input-inline">\n' +
                            '                                <input class="layui-input" name="maintain_base_param_edit" value=""/>\n' +
                            '                            </div>\n' +
                            '                            <div class="layui-input-inline">\n' +
                            '                                <input type="checkbox" checked="" name="open_edit" lay-skin="switch" lay-filter="switchTest" lay-text="是|否"><span>点亮数据</span>\n' +
                            '                            </div>\n' +
                            '                        </div>\n' +
                            '                        <div class="layui-input-inline">\n' +
                            '                            <a href="javascript:;" class="layui-text-red param_del" onclick="this.parentNode.parentNode.remove(this);">删除</a>\n' +
                            '                        </div>\n' +
                            '                    </div>\n' +
                            '                </div>' +
                            '             </form>';
                        body.find(".param_add_box_wrap_edit").append(param_add_box);
                        var param_select = body.find("select[name=maintain_base_choose_param]");
                        for(var i=0;i<paramData.length;i++){
                            param_select.append("<option>"+paramData[i]+"</option>")
                        }
                    }
                    ,yes: function (layero, index) {
                        layer.alert("确定按钮");
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                    ,btn2: function (layero, index) {
                        layer.alert("取消按钮")
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                layer.full(index);
            }
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#date'
        });
        $("#addBrand").click(function () {
            var index = layer.open({
                type: 2
                ,id: (new Date()).valueOf()
                ,title: '新增品牌'
                ,content: 'add.html'
                ,area: ['500px', '500px']
                ,btn: ['确定', '取消']
                ,maxmin: true
                ,success: function(layero, index){
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                }
            });
            layer.full(index);
        });
        $("#addParam").click(function () {
            var index = layer.open({
                type: 2
                ,id: (new Date()).valueOf()
                ,title: '新增品牌'
                ,content: 'param.html'
                ,area: ['500px', '500px']
                ,btn: ['确定', '取消']
                ,maxmin: true
                ,success: function(layero, index){
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                }
            });
            layer.full(index);
        })
        form.render();
    });
    //输出模块
    e("list", {})
});